<template>
  
  <van-form @submit="register">
    <van-field
      v-model="user.phone"
      name="手机号"
      label="手机号"
      placeholder="手机号"
      :rules="[{ required: true, message: '请填写手机号' }]"
    />
     <van-field
      v-model="user.nickname"
      name="昵称"
      label="昵称"
      placeholder="昵称"
      :rules="[{ required: true, message: '请填写昵称' }]"
    />
    <van-field
      v-model="user.password"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
    <div style="margin: 16px;">
      <van-button round block type="info" native-type="submit" @click="register">注册</van-button>
    </div>
  </van-form>
</template>

<script>
// import axios from "axios"
import { reqregister } from "../../http/http";
import { Toast } from 'vant';
export default {
  data() {
    return {
      //1.初始化表单数据
      user: {
        phone: "",
        nickname: "",
        password: ""
      }
    };
  },
  methods: {
    // 2.点了注册按钮
    register() {
      //发请求
      reqregister(this.user).then(res => {
        if (res.data.code === 200) {
          //注册成功
          Toast(res.data.msg);
          //跳转到登录
          this.$router.push("/login");
        } else {
          // 注册失败
          Toast(res.data.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
.registerbox {
  text-align: center;
  margin-top: 100px;
}
</style>